<template>
  <div class="app-container flex-cloumn">
    <el-row :gutter="12">
      <el-col :span="4">
        <el-form-item label="产品类型">
          <dictCombox v-model="queryConfigParams.productType"
                      :style="{width: '100%'}"
                      dictType="productType"
                      prop="productType"
                      @change="handleProductChange" size="small"></dictCombox>
        </el-form-item>
      </el-col>
      <el-col :span="4">
        <el-form-item>
          <el-button type="primary" icon="Search" size="small"
                     v-hasPermi="['pricingconfig:configmanage:list']"
                     style="margin: 3px 3px" @click="handlePriceCfgQuery">搜索
          </el-button>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row :gutter="12" style="margin: 0px 1px">
      <el-button
          type="primary"
          style="margin: 3px 3px"
          icon="Plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['pricingconfig:configmanage:add']"
      >新增
      </el-button>
      <el-button
          type="success"
          style="margin: 3px 3px"
          icon="Edit"
          size="small"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['pricingconfig:configmanage:edit']"
      >修改
      </el-button>
      <el-button
          type="danger"
          style="margin: 3px 3px"
          icon="Delete"
          size="small"
          :disabled="single"
          @click="handleDelete"
          v-hasPermi="['pricingconfig:configmanage:remove']"
      >删除
      </el-button>
      <el-button
          type="primary"
          style="margin: 3px 3px"
          size="small"
          :disabled="single"
          @click="handleDefault"
          v-hasPermi="['pricingconfig:configmanage:default']"
      >设置默认
      </el-button>
      <el-button
          type="danger"
          style="margin: 3px 3px"
          icon="Edit"
          size="small"
          :disabled="single||alloFlag"
          @click="handleUpdateAllocate"
          v-hasPermi="['pricingconfig:configmanage:allocate']"
      >授权
      </el-button>

    </el-row>

    <xTable v-loading="loading" ref="refPriceTable" refId="refPriceTable" multiple="false"
            @selection-change="handlePriceSelectionChange" class="tableDragger_form"
            :data="priceList">
      <template #columList>
        <el-table-column label="序号" type="index" width="150"/>
        <el-table-column label="定价配置代码" align="left" width="250" prop="cfg_id"></el-table-column>
        <el-table-column label="定价配置名称" align="left" prop="cfg_name" width="250"
                         :show-overflow-tooltip="true"></el-table-column>

        <el-table-column label="默认配置" align="left" width="200" prop="is_default" v-if="true">

          <template #default="scope">
            <span>{{ scope.row.is_default === '1' ? "是" : "否" }}</span>
          </template>
        </el-table-column>

        <el-table-column label="创建人" align="left" prop="user_name" width="200" v-if="true"/>

        <el-table-column label="权限" align="left" prop="cfg_right" width="200">
          <template #default="scope">
            <dict-tag :options="roleType" :value="scope.row.cfg_right"/>
          </template>
        </el-table-column>

        <el-table-column label="备注" align="left" prop="remark" class-name="small-padding fixed-width"
                         :show-overflow-tooltip="true"
                         v-if="true"></el-table-column>
      </template>
    </xTable>
    <pagination
        v-show="priceTotal>0"
        :total="priceTotal"
        v-model:page="queryConfigParams.pageNum"
        v-model:limit="queryConfigParams.pageSize"
        style="float:right"
        @pagination="getPriceCfgList"
    />


    <!-- 添加或修改 定价配置管理 对话框 -->
    <el-dialog :title="priceTitle" v-model="priceCfgOpen" width="500px" draggable :close-on-click-modal="false"
               destroy-on-close append-to-body>

      <el-form ref="priceCfgRef" :model="priceCfgForm" :rules="priceCfgRules" label-width="110px">
        <el-form-item label="产品类型">
          <dictCombox v-model="priceCfgForm.productType" dictType="productType" prop="productType" disabled
                      @change="handleProductChange" size="small"></dictCombox>
        </el-form-item>
        <el-form-item label="定价配置代码" prop="cfgId">
          <el-input v-model="priceCfgForm.cfgId" :disabled="disableFlag" maxlength="15"
                    placeholder="请输入定价配置代码"/>
        </el-form-item>
        <el-form-item label="定价配置名称" prop="cfgName">
          <el-input v-model="priceCfgForm.cfgName" :disabled="formShow.cfgName" maxlength="15" placeholder="请输入定价配置名称"/>
        </el-form-item>

        <!--        <el-form-item label="权限分配" prop="cfgRight" v-if="formShow.cfgRight">-->
        <!--          <dictCombox v-model="priceCfgForm.cfgRight" filterKey="1,2" dictType="roleType" size="small"></dictCombox>-->
        <!--        </el-form-item>-->


        <el-form-item label="权限分配" prop="cfgRight" v-if="formShow.allocateDeptAndUser">
          <el-tree
              class="tree-border"
              :data="deptUserOptions"
              show-checkbox
              ref="deptUserPermRef"
              node-key="id"
              :default-expanded-keys="defaultUser"
              :default-checked-keys="workmates"
              :default-expand-all="deptUserPermExpend"
              @check="checkChange"
              empty-text="加载中，请稍候"
              style="margin-bottom:10px"
              :props="{ label: 'label',type:'type', children: 'children' }"
          >
            <template #default="{ node, data }">
                    <span>
                    <span>{{ node.label }}</span>
                      <span v-if="data.type==='u'">
                        &nbsp;&nbsp;&nbsp;&nbsp;
                      </span>
                    <span v-if="data.type==='u'">
                      <el-radio-group v-model="treeRadio[data.id.split(':')[1]]" @change="radioChange">
                        <el-radio :label=getReadLabel(data.id)>读权限</el-radio>
                        <el-radio :label=getWriteLabel(data.id)>写权限</el-radio>
                      </el-radio-group>
                    </span>
                  </span>
            </template>
          </el-tree>
        </el-form-item>
        <el-form-item label="备注" prop="remark" v-if="formShow.remark">
          <el-input v-model="priceCfgForm.remark" type="textarea" rows="3" maxlength="100" show-word-limit
                    placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>

    </el-dialog>


    <!--授权对话框-->
    <el-dialog :title="allocateTitle" v-model="allocateOpen" draggable="true"
               :close-on-click-modal="false" width="1000px" :height="dialogHeight" append-to-body>
      <el-row :gutter="20">
        <!--部门数据-->
        <el-col :span="4" :xs="24">
          <div class="head-container">
            <el-input
                v-model="deptName"
                placeholder="请输入部门名称"
                clearable
                prefix-icon="el-icon-search"
                style="margin-bottom: 20px"
            />
          </div>
          <div class="head-container">
            <el-tree
                :data="deptOptions"
                :props="{ label: 'label', children: 'children' }"
                :expand-on-click-node="false"
                :filter-node-method="filterNode"
                ref="deptTreeRef"
                default-expand-all
                @node-click="handleNodeClick"
            />
          </div>
        </el-col>
        <!--用户数据-->
        <el-col :span="20" :xs="24">
          <el-form :model="allocateQueryParams" ref="allocateQueryRef" :inline="true">
            <el-row>
              <el-form-item label="用户编号" prop="userName">
                <el-input
                    v-model="allocateQueryParams.userName"
                    placeholder="请输入用户编号"
                    clearable
                    @keyup.enter="handleAllocateQuery"
                />
              </el-form-item>
              <el-form-item label="用户名称" prop="nickName">
                <el-input
                    v-model="allocateQueryParams.nickName"
                    placeholder="请输入用户名称"
                    clearable
                    @keyup.enter="handleAllocateQuery"
                />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="Search" size="small" @click="handleAllocateQuery">搜索</el-button>
              </el-form-item>
            </el-row>
          </el-form>
          <el-row :gutter="10" class="mb8" style="margin-top:5px">
            <el-col :span="1.5">
              <el-button
                  type="success"
                  icon="Edit"
                  size="small"
                  :disabled="allocateMultiple || adminShow"
                  v-show="rows[0].cfg_right >= 2"
                  @click="handleWriteDefault"
              >写权限
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                  type="success"
                  icon="Edit"
                  size="small"
                  v-show="rows[0].cfg_right >= 1"
                  :disabled="allocateMultiple || adminShow"
                  @click="handleReadDefault"
              >读权限
              </el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button
                  type="success"
                  icon="Edit"
                  size="small"
                  :disabled="allocateMultiple || adminShow"
                  @click="handleNoneDefault"
              >取消权限
              </el-button>
            </el-col>

          </el-row>
          <xTable ref="allocateUserTable" refId="allocateUserTable"
                  v-loading="allocateLoading" :data="allocateUserList"
                  class="tableDragger_form"
                  :style="{height:screenHeight , overflow:'auto'}"
                  @selection-change="allocateUserHandleSelectionChange">
            <template #columList>
              <el-table-column label="用户编号" align="center" prop="userName" :show-overflow-tooltip="true"/>
              <el-table-column label="用户名称" align="center" prop="nickName" :show-overflow-tooltip="true"/>
              <el-table-column label="所属部门" align="center" prop="deptName" :show-overflow-tooltip="true"/>
              <el-table-column label="定价名称" align="center" prop="cfgName" :show-overflow-tooltip="true"/>
              <el-table-column label="读写权限" align="center" prop="cfgRight" class-name="small-padding fixed-width">
                <template #default="scope">
                  <dict-tag :options="roleType" :value="scope.row.status"/>
                </template>
              </el-table-column>
            </template>
          </xTable>
          <pagination
              v-show="allocateUserTotal > 0"
              :total="allocateUserTotal"
              v-model:page="allocateQueryParams.pageNum"
              v-model:limit="allocateQueryParams.pageSize"
              @pagination="getAllocateUser"
          />
        </el-col>
      </el-row>
    </el-dialog>

  </div>
</template>

<script setup name="ConfigManage">
import {ref} from "vue";
import {isVoid, isNotVoid} from "@/utils/util";
import {
  deletePricingConfig,
  getPricUserPriceList,
  queryGroupPricingConfigAuthorByPage,
  savePricingConfig,
  updatePricingConfig,
  updatePricingConfigUserAuthor,
  updateUserDefaultPricingParam,
  getCfgUserAndDpetPerm,
  updateCfgPerm,
  listAllocateUser,
  querySubCfgCountByCfgId
} from "../../../api/pricingconfig/configmanage";
import {treeselectuser, treeselect} from "@/api/system/dept";

const {proxy} = getCurrentInstance();
const {productType, roleType} = proxy.useDict("productType", 'roleType');
// 用户组列表
const priceList = ref([]);

const priceCfgOpen = ref(false);

const priceTitle = ref('');

const loading = ref(true);
const disableFlag = ref(false);
//
const ids = ref([]);
//索引
const indexs = ref([]);
//数据
const rows = ref([]);

const single = ref(true);
const multiple = ref(true);
const priceTotal = ref(0);
const action = ref('');
const alloFlag = ref(true);
import store from '@/store'

const defaultUser = ref(['u:' + store.getters.user.userId])


const deptUserPermRef = ref(undefined);
const deptUserOptions = ref(undefined);
const deptUserPermExpend = ref(false);
const deptId = ref();

//授权对话框
const allocateUserList = ref([]);
const allocateTitle = ref("");
const allocateOpen = ref(false);
const allocateLoading = ref(true);
const allocateUserTotal = ref(0);
const deptOptions = ref(undefined);
const deptName = ref("");
const userIds = ref([]);
const adminShow = ref(false);
const allocateSingle = ref(true);
const allocateMultiple = ref(true);
const mainScreenHeight = ref(document.documentElement.clientHeight - 250 + "px");
const screenHeight = ref(document.documentElement.clientHeight - 350 + "px");
const dialogHeight = ref(document.documentElement.clientHeight - 200 + "px");

const workmates = ref([]);

const data = reactive({
  treeRadio:[],
  priceCfgForm: {
    productType: null,
    cfgId: null,
    cfgName: null,
    allocateDeptAndUser: [],
    remark: null,
    cfgRight: '2',
  },
  queryConfigParams: {
    pageNum: 1,
    pageSize: 20,
    productType: 'OtcOption'
  },
  priceCfgRules: {
    cfgId: [{required: true, message: "定价配置代码不能为空", trigger: "blur"}, {
      message: "不能输入中文",
      trigger: "blur",
      validator: (rule, value, callback) => {
        return escape(value).indexOf("%u") < 0
      },
    }],
    cfgName: [{required: true, message: "定价配置名称不能为空", trigger: "blur"}],
    cfgRight: [{required: true, message: "授权类型不能为空", trigger: "change"}],
  },
  formShow: {
    productType: true,
    allocateDeptAndUser: true,
    cfgId: true,
    cfgName: true,
    remark: true,
    cfgRight: true,
  },
  allocateQueryParams: {
    pageNum: 1,
    pageSize: 10,
    deptId: undefined,
    deptName: undefined,
    userName: undefined,
    nickName: undefined,
    cfgId: undefined
  },
});
const {
  queryConfigParams,
  priceCfgForm,
  priceCfgRules,
  formShow,
  allocateQueryParams,
  treeRadio
} = toRefs(data);


/** 查询按钮 */
function handlePriceCfgQuery() {
  getPriceCfgList();
}

/** 查询定价配置列表 */
function getPriceCfgList() {
  if (isVoid(queryConfigParams.value.productType)) {
    priceList.value = [];
    priceTotal.value = 0;
  } else {
    loading.value = true;
    getPricUserPriceList(queryConfigParams.value).then(response => {
      priceList.value = response.list;
      priceTotal.value = response.total;
      loading.value = false;
    });
  }
}


/** 通过条件过滤节点  */
const filterNode = (value, data) => {
  if (!value) return true;
  return data.label.indexOf(value) !== -1;
};
/** 根据名称筛选部门树 */
watch(deptName, val => {
  proxy.$refs["deptTreeRef"].filter(val);
});

/** 查询部门下拉树结构 */
function getTreeselect() {
  treeselect().then(response => {
    deptOptions.value = response.data;
    handleNodeClick({id: store.getters.user.deptId});
  });
};

/** 节点单击事件 */
function handleNodeClick(data) {
  allocateQueryParams.value.deptId = data.id;
  handleAllocateQuery();
};

//点击授权里的搜索按钮
function handleAllocateQuery() {
  allocateQueryParams.value.pageNum = 1;
  getAllocateUser();
}


/** 查询部门用户下拉树结构 */
function getTreeselectuser() {
  treeselectuser().then(response => {
    deptUserOptions.value = response.data;
  });

};

/**获取当前选中的所有节点 */
function getAllCheckedDeptAndUsers() {
  var checkedBox = deptUserPermRef.value.getCheckedNodes();
  var halfCheckedBox = deptUserPermRef.value.getHalfCheckedNodes();
  var valueIDArrs = []
  var valueTitleArrs = []
  checkedBox.forEach(element => {
    valueIDArrs.push(element.id);
    valueTitleArrs.push(element.label)
  })
  halfCheckedBox.forEach(element => {
    valueIDArrs.push(element.id);
    valueTitleArrs.push(element.label)
  })
  priceCfgForm.value.allocateDeptAndUser = valueIDArrs.join(",")

}


function allocateUserHandleSelectionChange(selection) {
  userIds.value = selection.map(item => item.userId);
  if (selection.length != 0) {
    deptId.value = selection[0].deptId;
  }
  if (userIds.value.includes(store.getters.user.userId) === true || userIds.value.includes(1) === true) {
    adminShow.value = true
  } else {
    adminShow.value = false
  }
  allocateSingle.value = selection.length != 1;
  allocateMultiple.value = !selection.length;
}


/** 查询定价配置列表 */
function handleProductChange() {
  getPriceCfgList();
}

/** 授权按钮操作 */
function handleUpdateAllocate() {
  reset();
  // defaultUser.value=['u:'+store.getters.user.userId];
  // deptUserPermExpend.value = true;
  // formShow.value.allocateDeptAndUser = true;
  // formShow.value.remark = false;
  // formShow.value.cfgName = true;
  // action.value = 'allocate';
  // disableFlag.value = true;
  // priceCfgForm.value.productType = rows.value[0].product_type;
  // priceCfgForm.value.cfgId = rows.value[0].cfg_id;
  // priceCfgForm.value.cfgName = rows.value[0].cfg_name;
  // priceCfgOpen.value = true;
  // priceTitle.value = "定价授权";
  //  const arrs =  getCfgUserAndDpetPerm(priceCfgForm.value).then(response =>{
  //   return response;
  // })

  // //回显
  // nextTick(() =>{
  // arrs.then((res) => {
  //   res.forEach((element) =>{
  //   nextTick(() =>{
  //     deptUserPermRef.value.setChecked(element,true,false)
  //       })
  //   })
  //   })
  // });

  allocateOpen.value = true;
  allocateTitle.value = "授权";
  allocateQueryParams.value.cfgId = rows.value[0].cfg_id;
  getTreeselect();

}

function getAllocateUser() {
  allocateLoading.value = true;
  listAllocateUser(allocateQueryParams.value).then(response => {
    allocateUserList.value = response.rows;
    allocateUserList.value.forEach(element => {
      element.cfgName = rows.value[0].cfg_name;
    })
    allocateUserTotal.value = response.total;
    allocateLoading.value = false;
  });
}

/**定价配置 新增按钮操作 */
function handleAdd() {
  reset();
  defaultUser.value = ['u:' + store.getters.user.userId];
  let tempWorkMates = [];
  let a = proxy.treeFindPath(deptUserOptions.value, node => {
    if (node.id == defaultUser.value) {
      return true;
    }
  });
  treeRadio.value = [];
  a[a.length - 2].children.forEach(item => {
    if (item.id.search("u:") != -1) {
      tempWorkMates.push(item.id);
      let uId = item.id.split(':')[1];
      if (uId == store.getters.user.userId) {
        treeRadio.value[uId] = uId + '-2';
      } else {
        treeRadio.value[uId] = uId + '-1';
      }
    }
  })
  workmates.value = tempWorkMates;
  disableFlag.value = false;
  priceCfgOpen.value = true;
  formShow.value.remark = true;
  formShow.value.cfgName = false;

  deptUserPermExpend.value = false;
  formShow.value.allocateDeptAndUser = true;
  formShow.value.cfgRight = true;

  priceTitle.value = "添加定价配置";
  priceCfgForm.value.productType = queryConfigParams.value.productType;
  action.value = 'add';
}

/**
 *
 * 定价配置  修改按钮操作
 * */
function handleUpdate() {
  if (rows.value[0].cfg_right === '1') {
    proxy.$modal.alertError("没有权限修改该数据");
    return;
  }
  reset();
  action.value = 'update';
  disableFlag.value = true;
  formShow.value.allocateDeptAndUser = false;
  formShow.value.cfgRight = false;
  formShow.value.remark = true;
  formShow.value.cfgName = false;
  priceCfgForm.value.productType = rows.value[0].product_type;
  priceCfgForm.value.cfgId = rows.value[0].cfg_id;
  priceCfgForm.value.cfgName = rows.value[0].cfg_name;
  priceCfgForm.value.remark = rows.value[0].remark;
  priceCfgOpen.value = true;
  priceTitle.value = "修改定价配置";
}

/**
 *
 * 修改/新增   保存操作
 * */
function submitForm() {
  proxy.$refs["priceCfgRef"].validate(valid => {
    if (valid) {
      if (action.value == 'update') {
        updatePricingConfig(priceCfgForm.value).then(response => {
          if (response.success) {
            proxy.$modal.msgSuccess("修改成功");
            priceCfgOpen.value = false;
            getPriceCfgList();
          } else {
            proxy.$modal.msgError(response.msg);
          }
        });
      } else if (action.value == 'add') {
        getAllCheckedDeptAndUsers();
        let addParam = proxy.lsh.cloneDeep(priceCfgForm.value);
        let radioArray = {};
        proxy.lsh.forEach(treeRadio.value, function (val, ky) {
          if (val != undefined && val != null && isNotVoid(val.split("-")[1])) {
            radioArray[val.split("-")[0]] = val.split("-")[1];
          }
        })
        proxy.lsh.assign(addParam, {'cfgRight': JSON.stringify(radioArray)});
        savePricingConfig(addParam).then(response => {
          if (response.success) {
            proxy.$modal.msgSuccess("新增成功");
            priceCfgOpen.value = false;
            getPriceCfgList();
          } else {
            proxy.$modal.msgError(response.msg);
          }
        });
      } else if (action.value == 'allocate') {
        getAllCheckedDeptAndUsers();
        updateCfgPerm(priceCfgForm.value).then(response => {
          if (response.success) {
            proxy.$modal.msgSuccess("授权成功");
            priceCfgOpen.value = false;
            getPriceCfgList();
          } else {
            proxy.$modal.msgError(response.msg);
          }
        })
      }
    }
  });
}


/** 写权限 */
function handleWriteDefault() {
  handleAuth('2');
}

/** 读权限 */
function handleReadDefault() {
  handleAuth('1');
}

/** 无权限 */
function handleNoneDefault() {
  handleAuth('0');
}

/** 分配权限操作 */
function handleAuth(cfgRight) {

  var params = {};
  params.cfgId = rows.value[0].cfg_id;
  params.userIds = userIds.value;
  params.deptId = deptId.value;
  params.cfgRight = cfgRight;
  params.productType = queryConfigParams.value.productType

  updatePricingConfigUserAuthor(params).then(response => {
    if (response.success) {
      proxy.$modal.msgSuccess("设置成功");
      getAllocateUser();
    } else {
      proxy.$modal.msgError(response.msg);
    }
  });

}


/**
 *
 * 设置默认 按钮操作
 * */
function handleDefault() {
  if (rows.value[0].cfg_right === '1') {
    proxy.$modal.alertError("没有权限设置默认");
    return;
  }
  var cfgId = ids.value[0];
  var param = {
    "cfgId": cfgId,
    "productType": queryConfigParams.value.productType
  };
  updateUserDefaultPricingParam(param).then(response => {
    if (response.success) {
      proxy.$modal.msgSuccess("设置成功");
      getPriceCfgList();
    } else {
      proxy.$modal.msgError(response.msg);
    }
  });
}


/**
 *
 * 多选框  选中数据
 * */
function handlePriceSelectionChange(selection) {
  if (selection.length === 1 && (selection[0].cfg_right == '2' || store.getters.user.userId == '1')) {
    alloFlag.value = false;
  } else {
    alloFlag.value = true;
  }

  if (selection.length == 0) {
    ids.value = [];
    indexs.value = [];
  } else {
    ids.value = selection.map(item => item.cfg_id);
    indexs.value = selection.map(item => item.index);
    rows.value = selection.map(item => item);
  }
  single.value = selection.length != 1;
  multiple.value = !selection.length;

}


/** 删除按钮操作 */
function handleDelete() {
  if (rows.value[0].cfg_right === '1') {
    proxy.$modal.alertError("没有权限删除该数据");
    return;
  }
  var params = {
    cfgId: rows.value[0].cfg_id
  };
  querySubCfgCountByCfgId(params).then(response => {
    if (response > 0) {
      proxy.$modal.alertError("该定价配置下有关联参数配置，请检查!");
    } else {
      deleteConfigManage();
    }
  });
}


function deleteConfigManage() {
  const cgfIds = ids.value;
  var params = {
    productType: rows.value[0].product_type,
    cfgId: rows.value[0].cfg_id
  };
  proxy.$modal.confirm('是否确认删除定价配置代码为 "' + cgfIds + '"的数据项？').then(function () {
    return deletePricingConfig(params);
  }).then(() => {
    getPriceCfgList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {
  });
}


/** 取消按钮 */
function cancel() {
  priceCfgOpen.value = false;
  reset();
}


/** 表单重置 */
function reset() {
  priceCfgForm.value = {
    cfgId: undefined,
    cfgName: undefined,
    remark: undefined,
    cfgRight: '1'
  };
  proxy.resetForm("priceCfgRef");
}


function checkChange(data, option) {
  let checkStatus = false;
  option.checkedKeys.forEach(function (option, index) {
    if (option == data.id) {
      checkStatus = true;
    }
  });
  if (data.id === defaultUser.value[0]) {
    deptUserPermRef.value.setChecked(data, true, true);
    treeRadio.value[data.id.split(":")[1]] = data.id.split(":")[1] + '-2';
  } else {
    let uId = data.id.split(":")[1];
    if (checkStatus) {
      if (treeRadio.value[uId] != undefined && treeRadio.value[uId].split('-')[1] == '2') {
        treeRadio.value[uId] = uId + '-2';
      } else {
        treeRadio.value[uId] = uId + '-1';
      }
      //如果为其他节点时处理子节点 读写
      let nodeArray = [];
      putChildOfTree(nodeArray, data);
      proxy.lsh.forEach(nodeArray, function (opt) {
        if (opt.id.split(':')[0] == 'u') {
          let uId2 = opt.id.split(':')[1];
          if ((treeRadio.value[uId2] != undefined && treeRadio.value[uId2].split('-')[1] == '2') || uId2 == defaultUser.value[0]) {
            treeRadio.value[uId2] = uId2 + '-2';
          } else {
            treeRadio.value[uId2] = uId2 + '-1';
          }
        }
      });
    } else {
      treeRadio.value[uId] = uId + '-0';
      //如果为其他节点时处理子节点 读写
      let nodeArray = [];
      putChildOfTree(nodeArray, data);
      proxy.lsh.forEach(nodeArray, function (opt) {
        if (opt.id.split(':')[0] == 'u') {
          let uId2 = opt.id.split(':')[1];
          if (uId2 === defaultUser.value[0].split(":")[1]) {
            deptUserPermRef.value.setChecked(defaultUser.value[0], true, true);
            treeRadio.value[uId2] = uId2 + '-2';
          } else {
            treeRadio.value[uId2] = uId2 + '-0';
          }
        }
      });
    }

  }
}

function getReadLabel(key) {
  let uId = key.split(":")[1];
  return uId + '-1';
}

function getWriteLabel(key) {
  let uId = key.split(":")[1];
  return uId + '-2';
}

function radioChange(value) {
  let uId = value.split("-")[0];
  if (uId == store.getters.user.userId) {
    treeRadio.value[uId] = uId + '-2';
  }
  deptUserPermRef.value.setChecked({id: 'u:' + uId}, true, true);
}

function putChildOfTree(nodeArray, data) {
  if (data.children != undefined && data.children != null && data.children.length > 0) {
    proxy.lsh.forEach(data.children, function (childData) {
      nodeArray.push(childData);
      putChildOfTree(nodeArray, childData);
    });
  }
}

onMounted(() => {
  setTimeout(() => {
    loading.value = false
  }, 300)
  window.onresize = function temp() {
    mainScreenHeight.value = document.documentElement.clientHeight - 250 + 'px;'
  }
})
getTreeselectuser();
getPriceCfgList();
</script>
